package com.mogist.hqc.module.main.adapter

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.View
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.mogist.hqc.R
import com.mogist.hqc.entitys.response.MainTypeVo
import talex.zsw.basecore.util.ColorTool
import talex.zsw.basecore.util.RegTool
import talex.zsw.basecore.util.glide.GlideTool

/**
 * 作用：类型
 * 作者：赵小白 email:vvtale@gmail.com  
 * 修改人：
 * 修改时间：
 * 修改备注：
 */
class TypeAdapter : BaseQuickAdapter<MainTypeVo, BaseViewHolder>(R.layout.item_main_type)
{
    override fun convert(helper: BaseViewHolder, item: MainTypeVo)
    { //iIcon iTvTitle
        helper.setText(R.id.iTvTitle, item.name)
        val image = helper.getView<ImageView>(R.id.iIcon)
        if (item.isSelect)
        {
            helper.setTextColor(R.id.iTvTitle,ColorTool.getColorById(R.color.text_orange))
            if (RegTool.isEmpty(item.iconUrl))
            {
                image.visibility = View.GONE
            }
            else
            {
                image.visibility = View.VISIBLE
                GlideTool.loadImg(image, item.iconUrl, ColorDrawable(Color.TRANSPARENT))
            }
        }
        else
        {
            helper.setTextColor(R.id.iTvTitle,ColorTool.getColorById(R.color.text_black2))
            image.visibility = View.GONE
        }
    }

    private var temp = -1
    fun setTemp(pos: Int)
    {
        temp = pos
    }

    fun getTemp(): Int
    {
        return temp
    }

    fun changeSelect(pos: Int):Boolean
    {
        if (temp == pos)
        {
            return false
        }
        if (temp >= 0)
        {
            data[temp].isSelect = false
        }
        if (data.size > pos)
        {
            data[pos].isSelect = true
            temp = pos
        }
        notifyDataSetChanged()
        return true
    }

    fun cleanTemp()
    {
        if (temp >= 0)
        {
            data[temp].isSelect = false
        }
        temp = -1
        notifyDataSetChanged()
    }
}